package demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class demo {

	public static void main(String[] args) throws Exception {
		// 1.注册驱动
		/*
		 * 
		 * Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver
		 * class is `com.mysql.cj.jdbc.Driver'.\ The driver is automatically registered
		 * via the SPI and manual loading of the driver class is generally unnecessary.
		 * 正在加载类`com.mysql.jdbc。驾驶员这是不赞成的。新的驱动程序类是`com.mysql.cj.jdbc。驾驶员驱动程序是通过SPI自动注册的，
		 * 通常不需要手动加载驱动程序类
		 */

//		Class.forName("com.mysql.cj.jdbc.Driver");

		// 2.获取连接
		String url = "jdbc:mysql://localhost:3306/newdatabases";
		String usename = "root";
		String passport = "chenjunxi66";
		Connection conn = DriverManager.getConnection(url, usename, passport);

		// 3.定义sql
		String sql = "update student set salary = 199990 where id = 1";

		// 4.取执行sql的对象statement
		Statement stm = conn.createStatement();

		// 5.执行sql语句
		int cnt;
		try {
			cnt = stm.executeUpdate(sql);
		} catch (Exception e) {
			// TODO: handle exception
		}

		// 6.处理结果
		System.out.println(cnt);
		
		//7.关闭资源
		stm.close();
        conn.close();

	}

}
